/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       timer.h
 * Author:     karooolek
 * Created on: 2009-01-06
 *
 **********************************************************************************************************************/

#ifndef TIMER_H_
#define TIMER_H_

#include "types.h"
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <sys/time.h>
#endif

namespace mGameEngine
{

/**
 * Timer.
 * Timer can be used for time, intervals and delays control.
 * It measures time in microseconds, based on OS clock.
 */
class Timer
{
protected:
    /**
     * Timer start
     */
    uint64 _start;

    /**
     * Timer last stop
     */
    uint64 _stop;

    /**
     * Get system clock time.
     * @return system clock time in microseconds.
     */
    static uint64 _clock();

public:
    /**
     * Create new timer.
     */
    Timer();

    /**
     * Create new timer with initial value.
     * @param time initial timer value in seconds.
     * @param running is timer running.
     */
    Timer(float time, bool running = true);

    /**
     * Destroy timer.
     */
    ~Timer();

    /**
     * Check if timer is running.
     * @return true if timer is running, false otherwise
     */
    bool isRunning() const;

    /**
     * Start timer.
     */
    void start();

    /**
     * Stop (pause) timer.
     */
    void stop();

    /**
     * Reset timer value beck to 0 seconds.
     */
    void reset();

    /**
     * Get time.
     * @return counted time in seconds
     */
    float getTime() const;

    /**
     * Set time.
     * @param sec timer value in seconds
     */
    void setTime(float sec);
};

}

#endif // TIMER_H_
